package com.grandbroad.eim.ui.fragment;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.easy.west.westclient.api.hotvod.bean.VodList;
import com.easy.west.westclient.api.hotvod.event.GetHotVodListEvent;
import com.grandbroad.eim.R;
import com.grandbroad.eim.adapter.ClassPageAdaapter;
import com.grandbroad.eim.app.MyApplication;
import com.grandbroad.eim.base.BaseFragment;
import com.grandbroad.eim.ui.activities.SearchActivity;
import com.grandbroad.eim.utils.ToastUtils;
import com.grandbroad.eim.utils.UiUtlis;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;


public class ClassFragment extends BaseFragment {


    @BindView(R.id.img_search)
    ImageView imgSearch;
    @BindView(R.id.tool_class_bar)
    Toolbar toolClassBar;
    @BindView(R.id.recycler_class_list)
    RecyclerView recyclerClassList;
    Unbinder unbinder;
    private ClassPageAdaapter pageAdaapter;
    @Override
    protected boolean setEventOpen() {
        return true;
    }

    @Override
    protected void initdata() {
        //请求推荐数据
        MyApplication.getMoleclient().getHotVod();
    }

    @Override
    protected void initview() {
        //设置toolbar
        activity.setSupportActionBar(toolClassBar);
        activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
        pageAdaapter = new ClassPageAdaapter((AppCompatActivity) getActivity());
        recyclerClassList.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerClassList.setAdapter(pageAdaapter);
        //搜索
        imgSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UiUtlis.startAnimActivity((AppCompatActivity) getActivity(),SearchActivity.class,imgSearch,"search_img",true);
            }
        });
    }

    @Override
    protected int setlayout() {
        return R.layout.fragment_class;
    }

    /**
     * 请求推荐列表
     * @param eva
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getVod(GetHotVodListEvent eva)
    {
        if (eva.isOk())
        {
            VodList list = eva.getBean();
            if (list.getStatus()==1)
            {
                pageAdaapter.setHotlist(eva.getBean().getData());
                pageAdaapter.notifyDataSetChanged();
            }
            else
            {
                ToastUtils.show("请求失败:"+list.getErrordescrip());
            }
        }
        else
        {
            ToastUtils.show("请求失败:"+eva.getCodeDescribe());
        }

    }

}
